package com.dyzx.hbb.aliyun.product;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(ProductProperties.class)
public class ProductAutoConfiguration {
    private final ProductProperties productProperties;

    public ProductAutoConfiguration(final ProductProperties productProperties) {
        this.productProperties = productProperties;
    }

    /**
     * Configuration productClient bean.
     *
     * @return the product client
     */
    @Bean
    @ConditionalOnMissingBean
    public ProductClient productClient() {

            return new ProductClient(
                    this.productProperties.getAppKey(),
                    this.productProperties.getAppSecret(),
                    this.productProperties.getAppCode());

    }
}
